package cn.laiyoufa.action;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import cn.laiyoufa.imple.VipDao;
import cn.laiyoufa.model.VipModel;

public class VipAction extends ActionSupport {
   VipDao dao=new VipDao();
   private VipModel vip;
   ArrayList<VipModel> list;
   HttpServletRequest request = ServletActionContext.getRequest();
   
   public String insert()
   {   //增加
     dao.insert(vip); 
	 return "inster";   
   }
   
   
   public String updata_show()
   {
	   String v_name=request.getParameter("v_name");
	   String v_type=request.getParameter("v_type");
	   String v_sex=request.getParameter("v_sex");
	   String v_number=request.getParameter("v_number");
	   String v_id = request.getParameter("v_id");
	   
	   VipModel vip2 = new VipModel();
	   vip2.setV_id(v_id);
	   vip2.setV_name(v_name);
	   vip2.setV_number(v_number);
	   vip2.setV_sex(v_sex);
	   vip2.setV_type(v_type);
	   
	   vip = vip2;
	   
	   return "alert";
   }
   
   
   public String update()
   {     //vip 修改
	   String i=dao.update(vip);
	   return "update";   
   }
   
   public String select(){	  	  
	   list=dao.select();	   
	   if(list!=null)
	   {
		   return "select";
	   }
	   else
	   {
		   return ERROR;
	   }	 
   }
   
   
    public String query()
    {
    	HttpServletRequest request=ServletActionContext.getRequest();
    	String type=request.getParameter("sele");
    	String key=request.getParameter("shuru");
    	
    	if(key==null||"".equals(key))
    	{
    		list=dao.select();	
    	}
    	else
    	{
    		list=dao.select_like(type, key);
    	}
    	
    	return "query";
    }
    
   public String delete()
   {
	   HttpServletRequest request=ServletActionContext.getRequest();
	   String v_id=request.getParameter("id");
	   String i=dao.delete(v_id);
	   
	  return "delete"; 
   }
   
   
  public VipModel getVip() 
  {
	return vip;
   }
   public void setVip(VipModel vip) 
   {
	this.vip = vip;
   }

  public ArrayList<VipModel> getList() {
	return list;
   }

  public void setList(ArrayList<VipModel> list) {
	this.list = list;
   }
   
}

